import 'dart:core';
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:kasax_demos2/entry/entrys.dart';
import 'package:kasax_demos2/widgets/posts_widgets.dart';

import 'sliver_list_demo.dart';

/// Scaffold 可视化空间，我们一般将Sliver放在CustomScrollView的slivers中
/// GridView == CustomScrollView(slivers:SliverGrid())
class SliverListDemoHome extends StatefulWidget {
  const SliverListDemoHome({Key? key}) : super(key: key);

  @override
  _SliverListDemoHomeState createState() => _SliverListDemoHomeState();
}

// SliverGridDelegateWithFixedCrossAxisCount设置交叉轴上的条目的数量
class _SliverListDemoHomeState extends State<SliverListDemoHome> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return PostsListWidget((BuildContext context, AsyncSnapshot<List<Posts>> snapshot) {
      log("PostsListWidget buildPageContent run...");
      return buildCustomScrollView(snapshot);
    });
  }

  CustomScrollView buildCustomScrollView(AsyncSnapshot<List<Posts>> asyncsnapshot) {
    return CustomScrollView(
      slivers: [
        // 显示在安全区域
        SliverSafeArea(
            // 添加内边距
            sliver: SliverListDemo(asyncsnapshot.data!))
      ],
    );
  }
}
